package com.infore.operation.utils;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

/**
 * HttpServletResponse帮助�?
 */
public class ResponseUtils {
	public static void outputJson(HttpServletResponse response, Object obj) {
		response.setCharacterEncoding("utf-8");
		PrintWriter out;
		try {
			Gson gson = new Gson();
			out = response.getWriter();
			out.println(gson.toJson(obj));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String changeCharacterEncoding(String str){
		try {
			str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
			return str;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
}
